#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include "list.h"

typedef struct _STU
{
    int id;
    char *pcName;
}STU;
int  debugList(LINK_LIST *pstList)/*从链表头节点之后开始遍历输出*/
{
    LIST_NODE *temp = NULL;
    int i = 1;
    if (pstList == NULL || pstList->pstHead == NULL)
    {
        printf("这是一个空表!\n");
        return -1;
    }
    temp = pstList->pstHead->pstNext;
    while (temp)
    {
        printf("第%d个结点值为：%s\n",i++,(char *)temp->pData);
        temp = temp->pstNext;
    }
    return 0;
}

int main(void)
{
    char *str[3] = {"shu xue :88","ying yu :77","di li : 99"};
    STU *pstStuTemp1,*pstStuTemp;
    int i;
    LINK_LIST *pstList = NULL;
    LIST_NODE *pstNodeTemp = NULL;
   
    pstStuTemp1 = (STU *)malloc(sizeof(STU));
    pstStuTemp1->id = 1;
    pstStuTemp1->pcName = "xiao ming ";
       /*********测试initList*******/
    pstList = (LINK_LIST *)malloc(sizeof(LINK_LIST));
    if (initList(pstList) == true)
        printf("initList succeed!\n");
    /*********测试createListHead************/
    pstNodeTemp = createNode( pstStuTemp1, sizeof(STU));
    if (pstNodeTemp == NULL)
        printf("pstNodeTemp malloc failed");
    createListHead(pstList, pstNodeTemp);
    pstStuTemp = (STU *)pstList->pstHead->pData;
    printf("pstList pstHead info: stu1 id:%d,stu1 pcName:%s\n", pstStuTemp->id,pstStuTemp->pcName);
    /**********测试addListTail**************/
    for (i = 0; i<1; i++)
    {
        pstNodeTemp = createNode(str[i], strlen(str[i]) + 1);
        addListTail(pstList, pstNodeTemp );
    }

    for (i = 0; i < 3; i++)
    {

        pstNodeTemp = createNode(str[i], strlen(str[i]) + 1);
        addListTail(pstList, pstNodeTemp );
    }

    printf("test the addListTail()\n");

    debugList(pstList);

    /*********测试delListNode*********************/

    pstNodeTemp = pstList->pstHead->pstNext;
    delListNode(pstList, pstNodeTemp);
    printf("test the delListNode\n");
    debugList(pstList);
    /*********测试insertListAfter************/
    pstNodeTemp = createNode(str[0], strlen(str[0]) + 1 );
    insertListAfter(pstList, pstList->pstHead, pstNodeTemp);
    printf("test the insertListAfter\n");
    debugList(pstList);
    /************测试freeList**********************/
    freeList(pstList);
    printf("test the freeList\n");
    debugList(pstList);
    free(pstList);
    free(pstStuTemp1);
    return 0;

}
